<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/main.css">
    <link rel="stylesheet" href="../css/jquery-ui.css">
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
    <title></title>
    <style>
        th{text-align: center;}
        .m0{margin: 0px;}
        #dialogLevel2Div{
            margin: 0px;
            padding: 0px;;
        }
        .title{
            height: 37px;
            line-height: 37px;
            background: url('../images/box_top.png') 0px 0px repeat-x;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="box_border" style="border-bottom: none;">
        <div class="title" onclick="toggleLevel(1)"><b class="pl15">部门审批权限管理</b></div>
        <div id="divLevel1" class="mt10">
            <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                    <tr >
                        <th >序号</th>
                        <th>姓名</th>
                        <th>部门</th>
                        <th>审批权限</th>
                        <th>报销权限</th>
                        <th>可选操作</th>
                    </tr>
                    <tbody id="tableLevel1">

                    </tbody>
                    </table>
                <div class="page mt10 fl">
                    <a class="ext_btn add mt10" onclick="addLevel1Leader()" ><span class="add" ></span>添加领导</a>
                    <!--<a class="ext_btn del mt10" ><span class="del" ></span>删除全部</a>-->
                </div>
                <div class="page  fr" style="margin-top: -10px;">
                    <div class="pagination">
                        <ul id="level1Ul">
                            <li class="first-child " id="Level1Li1"><a onclick="firstLastLevel1Page(0)">首页</a></li>
                            <li class="" id="Level1Li2"><a onclick="upDownLevel1Page(-1)">上一页</a></li>
                            <li class="" id="Level1Li3"><a onclick="upDownLevel1Page(1)">下一页</a></li>
                            <li class="last-child " id="Level1Li4"><a onclick="firstLastLevel1Page(1)">末页</a></li>
                        </ul>
                    </div>
                </div>
                <div id="dialogLevel1Div" title="" style="display: none;">
                    <form name="from1" >
                        <div class="pb10 mb15 disabled "> <div style="display: inline-block;width:82px;text-align: right;">用户名称:</div>
                            <input type="text" name="level1UserName" class="input-text lh30 ml disabled" id="level1UserName" size="23"  readonly><span style="color:red;font-size: 20px;">&nbsp;*</span>
                            <input type="text" name="level1UserId" class="input-text lh30 ml disabled" id="level1UserId" size="23" style="display: none;" readonly>
                        </div>
                        <div class="pb10 mb15"> <div style="display: inline-block;width:82px;text-align: right;" >部门:</div>
                            <select name="Level1SelectSection" id="Level1SelectSection" class="select ml" style="width: 175px;" >
                            </select>
                        </div>
                        <div class="pb10 mb15"> <div style="display: inline-block;width:82px;text-align: right;" >权限:</div>
                            <input type="checkbox" name="Level1Check"  id="Level1IsApprove" size="30"  style="margin: 0 3px 5px 0">审批权限
                            <input type="checkbox" name="Level1Check"  id="Level1IsFee" size="30"  style="margin: 0 3px 5px 0">财务权限
                        </div>
                    </form>
                </div >
                <div id="dialogLevel1AddDiv" title="" style="display: none;">
                    <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                        <tr>
                            <th style="width: 8%;">序号</th>
                            <th>账号</th>
                            <th>姓名</th>
                            <th style="width: 15%;">可选操作</th>
                        </tr>
                        <tbody id="Level1AddTable">
                        </tbody>
                    </table>
                    <div class="page  fl" style="margin-top: -8px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <input type="text" id="level1SearchText" name="search" class="input-text lh30" size="20">
                            <input type="button" value="搜索" class="ext_btn ext_btn_submit" onclick="addLevel1Search()">
                            <input type="button" value="全部人员"  class="ext_btn ext_btn_submit" onclick="addLevel1AllUser()">
                        </div>
                    </div>
                    <div class="page  fr" style="margin-top: -10px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <ul id="addLevel1Ul">
                                <li class="first-child " id="addLevel1Li1"><a onclick="firstLastAddLevel1Page(0)">首页</a></li>
                                <li class="" id="addLevel1Li2"><a onclick="upDownAddLevel1Page(-1)">上一页</a></li>
                                <li class="" id="addLevel1Li3"><a onclick="upDownAddLevel1Page(1)">下一页</a></li>
                                <li class="last-child " id="addLevel1Li4"><a onclick="firstLastAddLevel1Page(1)">末页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
<div class="box">
    <div class="box_border" style="border-bottom: none;">
        <div class="title" onclick="toggleLevel(2)"><b class="pl15">分管签批权限管理</b></div>
        <div id="divLevel2" class="mt10">
            <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                    <tr>
                        <th>序号</th>
                        <th>账号</th>
                        <th>姓名</th>
                        <th>可选操作</th>
                    </tr>
                    <tbody id="tableLevel2">

                    </tbody>
                </table>
                <div class="page mt10 fl">
                    <a class="ext_btn add mt10" onclick="addLevel2Leader()" ><span class="add" ></span>添加领导</a>
                    <!--<a class="ext_btn del mt10" ><span class="del" ></span>删除全部</a>-->
                </div>
                <div class="page  fr" style="margin-top: -10px;">
                    <div class="pagination">
                        <ul id="level2Ul">
                            <li class="first-child " id="Level2Li1"><a onclick="firstLastLevel2Page(0)">首页</a></li>
                            <li class="" id="Level2Li2"><a onclick="upDownLevel2Page(-1)">上一页</a></li>
                            <li class="" id="Level2Li3"><a onclick="upDownLevel2Page(1)">下一页</a></li>
                            <li class="last-child " id="Level2Li4"><a onclick="firstLastLevel2Page(1)">末页</a></li>
                        </ul>
                    </div>
                </div>
                <div id="dialogLevel2Div" style="display: none;">
                    <!--<div id="tabLevel2Div">-->
                        <ul>
                            <li><a href="#level2IsApproveTab">审批权限</a></li>
                            <li><a href="#level2IsFeeTab">财务权限</a></li>
                        </ul>
                        <div id="level2IsApproveTab">
                    <form name="from1" >
                        <!--<div class="pb10 mb15 disabled " style="display: none;"> <div style="width:82px;text-align: right;">用户名称:</div>-->
                            <!--<input type="text" name="level1UserName" class="input-text lh30 ml disabled" id="level2UserName" size="23"  readonly><span style="color:red;font-size: 20px;">&nbsp;*</span>-->
                            <!--<input type="text" name="level1UserId" class="input-text lh30 ml disabled" id="level2UserId" size="23"  readonly>-->
                        <!--</div>-->
                        <div class="pb10"> <div style="display: inline-block;width:46px;text-align: right;" >部门:</div>
                            <select name="Level1IsApproveSelectSection" id="Level2IsApproveSelectSection" class="select ml" style="width: 175px;" >
                            </select>
                            <a class="ext_btn add mt10" onclick="level2IsApproveAddSection()" ><span class="add" ></span>添加</a>
                            <a class="ext_btn add mt10 " onclick="level2IsApproveClearSection()" ><span class="del" ></span>清除</a>
                        </div>
                        <div > <div style="display: inline-block;width:46px;text-align: right;" ></div>
                            <textarea id="level2IsApproveSection" style="width: 298px;height: 150px;resize:none; background-color: #f1f8ff;border: 1px solid #ccc" readonly></textarea>
                        </div>
                        <div > <div style="display: inline-block;width:46px;text-align: right;" ></div>
                            <a class="ext_btn modify mt10" onclick="level2IsApproveSaveSection()" ><span class="modify" ></span>保存</a>
                        </div>
                        <!--<div class="pb10 mb15"> <div style="display: inline-block;width:82px;text-align: right;" >权限:</div>-->
                            <!--<input type="checkbox" name="Level1Check"  id="Level2IsApprove" size="30"  style="margin: 0 3px 5px 0">审批权限-->
                            <!--<input type="checkbox" name="Level1Check"  id="Level2IsFee" size="30"  style="margin: 0 3px 5px 0">财务权限-->
                        <!--</div>-->
                    </form>
                        </div>
                    <div id="level2IsFeeTab">
                        <form name="from2" >
                            <div class="pb10"> <div style="display: inline-block;width:46px;text-align: right;" >部门:</div>
                                <select name="Level2IsFeeSelectSection" id="Level2IsFeeSelectSection" class="select ml" style="width: 175px;" >
                                </select>
                                <a class="ext_btn add mt10" onclick="level2IsFeeAddSection()" ><span class="add" ></span>添加</a>
                                <a class="ext_btn add mt10 " onclick="level2IsFeeClearSection()" ><span class="del" ></span>清除</a>
                            </div>
                            <div > <div style="display: inline-block;width:46px;text-align: right;" ></div>
                                <textarea id="level2IsFeeSection" style="width: 298px;height: 150px;resize:none; background-color: #f1f8ff;border: 1px solid #ccc" readonly></textarea>
                            </div>
                            <div > <div style="display: inline-block;width:46px;text-align: right;" ></div>
                                <a class="ext_btn modify mt10" onclick="level2IsFeeSaveSection()" ><span class="modify" ></span>保存</a>
                            </div>
                        </form>
                    </div>
                    <div id="dialogLevel2AddDiv" title="" style="display: none;">
                        <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                            <tr>
                                <th style="width: 8%;">序号</th>
                                <th>账号</th>
                                <th>姓名</th>
                                <th style="width: 15%;">可选操作</th>
                            </tr>
                            <tbody id="Level2AddTable">
                            </tbody>
                        </table>
                        <div class="page  fl" style="margin-top: -7px; margin-bottom: 0;">
                            <div class="pagination" style="margin-bottom: 0;">
                                <input type="text" id="level2SearchText" name="search" class="input-text lh30" size="20">
                                <input type="button" value="搜索" class="ext_btn ext_btn_submit" onclick="addLevel2Search()">
                                <input type="button" value="全部人员"  class="ext_btn ext_btn_submit" onclick="addLevel2AllUser()">
                            </div>
                        </div>
                        <div class="page  fr" style="margin-top: -10px; margin-bottom: 0;">
                            <div class="pagination" style="margin-bottom: 0;">
                                <ul id="addLevel2Ul">
                                    <li class="first-child " id="addLevel2Li1"><a onclick="firstLastAddLevel2Page(0)">首页</a></li>
                                    <li class="" id="addLevel2Li2"><a onclick="upDownAddLevel2Page(-1)">上一页</a></li>
                                    <li class="" id="addLevel2Li3"><a onclick="upDownAddLevel2Page(1)">下一页</a></li>
                                    <li class="last-child " id="addLevel2Li4"><a onclick="firstLastAddLevel2Page(1)">末页</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                <!--</div>-->
                </div>
            </div>
        </div>
    </div>
</div>
<div class="box">
    <div class="box_border" style="border-bottom: none;">
        <div class="title" onclick="toggleLevel(3)"><b class="pl15">领导签批权限管理</b></div>
        <div id="divLevel3" class="mt10">
            <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                    <tr >
                        <th>序号</th>
                        <th>姓名</th>
                        <th>审批权限</th>
                        <th>报销权限</th>
                        <th>可选操作</th>
                    </tr>
                    <tbody id="tableLevel3">

                    </tbody>
                </table>
                <div class="page mt10 fl">
                    <a class="ext_btn add mt10" onclick="addLevel3Leader()" ><span class="add" ></span>添加领导</a>
                    <!--<a class="ext_btn del mt10" ><span class="del" ></span>删除全部</a>-->
                </div>
                <div id="dialogLevel3AddDiv" title="" style="display: none;">
                    <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                        <tr>
                            <th style="width: 8%;">序号</th>
                            <th>账号</th>
                            <th>姓名</th>
                            <th style="width: 15%;">可选操作</th>
                        </tr>
                        <tbody id="Level3AddTable">
                        </tbody>
                    </table>
                    <div class="page  fl" style="margin-top: -7px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <input type="text" id="level3SearchText" name="search" class="input-text lh30" size="20">
                            <input type="button" value="搜索" class="ext_btn ext_btn_submit" onclick="addLevel3Search()">
                            <input type="button" value="全部人员"  class="ext_btn ext_btn_submit" onclick="addLevel3AllUser()">
                        </div>
                    </div>
                    <div class="page  fr" style="margin-top: -10px; margin-bottom: 0;">
                        <div class="pagination" style="margin-bottom: 0;">
                            <ul id="addLevel3Ul">
                                <li class="first-child " id="addLevel3Li1"><a onclick="firstLastAddLevel3Page(0)">首页</a></li>
                                <li class="" id="addLevel3Li2"><a onclick="upDownAddLevel3Page(-1)">上一页</a></li>
                                <li class="" id="addLevel3Li3"><a onclick="upDownAddLevel3Page(1)">下一页</a></li>
                                <li class="last-child " id="addLevel3Li4"><a onclick="firstLastAddLevel3Page(1)">末页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div id="dialogLevel3Div" title="" style="display: none;">
                    <form name="from1" >
                        <div class="pb10 mb15 disabled "> <div style="display: inline-block;width:82px;text-align: right;">用户名称:</div>
                            <input type="text" name="level3UserName" class="input-text lh30 ml disabled" id="level3UserName" size="23"  readonly><span style="color:red;font-size: 20px;">&nbsp;*</span>
                            <input type="text" name="level3UserId" class="input-text lh30 ml disabled" id="level3UserId" size="23" style="display: none;" readonly>
                        </div>
                        <div class="pb10 mb15"> <div style="display: inline-block;width:82px;text-align: right;" >权限:</div>
                            <input type="checkbox" name="Level3Check"  id="Level3IsApprove" size="30"  style="margin: 0 3px 3px 0">审批权限
                            <input type="checkbox" name="Level3Check"  id="Level3IsFee" size="30"  style="margin: 0 3px 3px 0">财务权限
                        </div>
                    </form>
                </div >
            </div>
        </div>
    </div>
</div>
<div id="info" style="display:none;text-align: center;"></div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript">
    $(function () {
        toggleLevel(1); //滑动
        //level1
        getUserPageCount();//获取页数
        firstLastLevel1Page(0);
        //level2
        firstLastLevel2Page(0);

        //level3
        getLevel3Limit();
//        alert(level1PageCounts);
//        addLevel1Leader();
    });
    //滑动
    function toggleLevel(e){
        var divLevel1=$("#divLevel1");
        var divLevel2=$("#divLevel2");
        var divLevel3=$("#divLevel3");
        switch (e){
            case 1:divLevel1.slideDown();divLevel2.slideUp();divLevel3.slideUp();break;
            case 2:divLevel2.slideDown();divLevel1.slideUp();divLevel3.slideUp();break;
            case 3:divLevel3.slideDown();divLevel2.slideUp();divLevel1.slideUp();break;
        }
    }
    //消息提示框
    function dialogInfo(e){
        $("#info").html(e).dialog({
            resizable: false,
            title: "信息",
            modal: true,
            buttons: {
                '确定': function () {
                    $("#info").dialog("close");
                }
            }
        });
        setTimeout('closeDialogInfo()',1000);
    }
    //关闭消息提示框
    function closeDialogInfo(){
        $("#info").dialog('close');
    }
    //获取页数
    function getUserPageCount(){
        var phpUrl=url+'admin/Leader/LeaderGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'getPageCount'},
            success: function (data) {
//                alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    level1PageCounts = Math.ceil(data.level1PageCounts/10);
                    level2PageCounts = Math.ceil(data.level2PageCounts/10);
                    level3PageCounts = Math.ceil(data.level3PageCounts/10);
                    if(level1PageCounts<=1) {level1PageCounts=1; $("#level1Ul li").addClass("disabled")} else{$("#level1Ul li").removeClass("disabled")}
                    if(level2PageCounts<=1) {level2PageCounts=1; $("#level2Ul li").addClass("disabled")} else{$("#level2Ul li").removeClass("disabled")}
                    if(level3PageCounts<=1) {level3PageCounts=1; $("#level3Ul li").addClass("disabled") }else{$("#level3Ul li").removeClass("disabled")}
                }
            }
        });
    }
    //**************************************************************
    //level1h函数
    var level1CurPage=0;
    var level1PageCounts=1;
    //加载表格
    function level1CreateTable(tableData){
        var i=0;
        var tableLevel1=$("#tableLevel1");
        tableLevel1.empty();
        for(;i<tableData.length;i++){
            if(tableData[i]['is_approve']==1) tableData[i]['is_approve']='有';else tableData[i]['is_approve']='无';
            if(tableData[i]['is_fee']==1) tableData[i]['is_fee']='有';else tableData[i]['is_fee']='无';
            tableLevel1.append(
                     '<tr><td class="td_center" >' +(i+1) + '</td>'+
                     '<td class="td_center  " style="display: none;" >' + tableData[i]['user_id'] + '</td>'+
                     '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                     '<td class="td_center  " >' + tableData[i]['section_name'] + '</td>'+
                     '<td class="td_center  " >' + tableData[i]['is_approve'] + '</td>'+
                     '<td class="td_center  " >' + tableData[i]['is_fee'] + '</td>'+
                     '<td class="td_center"><a class="ext_btn modify" onclick="editLevel1(this)" ><span class="modify" ></span>权限编辑</a>'+
                     '<a class="ext_btn del" onclick="deleteLevel1(this)" ><span class="del" ></span>删除</a></td></tr>'
             );
        }
    }
    //获取当前页数据
    function getLevel1Limit(n,m){
        var phpUrl=url+'admin/Leader/LeaderLevel1GetLimit.php';
        $.ajax({
            url:phpUrl,
            type:'POST',
            async:true,
            data:{model:'getLevel1Limit',n:n,m:m},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    level1CreateTable(data.data);
                }
            }
        });
    }
    //添加领导
    function addLevel1Leader(){
        $("#dialogLevel1AddDiv").dialog({
            position: { my: "top-300px", at: "center", of: window  } ,
            title:'添加部门审批领导',
            resizable:false,
            width:600
        });
        addLevel1GetPageCount();
        addLevel1GetUserLimit(0,10);
    }
    var addLevel1CurPage=0;
    var addLevel1PageCounts=1;
    //添加领导之加载人员
    function addLevel1GetUserLimit(n,m){
        var phpUrl=url+'admin/Leader/LeaderLevel1AddGetUserLimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'addLevel1GetUserlimit',n:n,m:m},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    var tableData=data.data;
                    var Level1AddTable=$("#Level1AddTable");
                    Level1AddTable.empty();
                    for(var i=0;i<tableData.length;i++){
                        Level1AddTable.append(
                                '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                '<td class="td_center"><a class="ext_btn add" onclick="addLevel1ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                        );
                    }
                }
            }
        });
    }
    //添加level1领导之加获取人员数量
    function addLevel1GetPageCount(){
        var phpUrl=url+'admin/Leader/LeaderLevel1AddGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'addLevel1GetPageCount'},
            success: function (data) {
//                alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    addLevel1PageCounts = Math.ceil(data.pageCount/10);
                    if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled") } else {$("#addLevel1Ul li").removeClass("disabled")}
                }
            }
        });
    }
    //添加level1领导之首尾页
    function firstLastAddLevel1Page(e){
//        alert(1);
        if(e==0) {
            addLevel1CurPage=0;
            $("#addLevel1Ul li").addClass("disabled");
            $("#addLevel1Li3").removeClass("disabled");
            $("#addLevel1Li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            addLevel1CurPage=addLevel1PageCounts-1;
            $("#addLevel1Ul li").addClass("disabled");
            $("#addLevel1Li1").removeClass("disabled");
            $("#addLevel1Li2").removeClass("disabled");
        }
        addLevel1GetUserLimit(addLevel1CurPage*10,10);
        if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled")}
    }
    //添加level1领导之上下页
    function upDownAddLevel1Page(e){
        if(addLevel1CurPage>=0||addLevel1CurPage<=addLevel1PageCounts-1){
            if(e<0){
                if(addLevel1CurPage>0)  {
                    addLevel1CurPage--;
                    if(addLevel1CurPage>0) $("#addLevel1Ul li").removeClass("disabled");
                    else{
                        $("#addLevel1Ul li").removeClass("disabled");
                        $("#addLevel1Li1").addClass("disabled");
                        $("#addLevel1Li2").addClass("disabled");
                    }
                }
            }else{
                if(addLevel1CurPage<addLevel1PageCounts-1) {
                    addLevel1CurPage++;
                    if(addLevel1CurPage<addLevel1PageCounts-1) $("#level1Ul li").removeClass("disabled");
                    else{
                        $("#addLevel1Ul li").removeClass("disabled");
                        $("#addLevel1Li3").addClass("disabled");
                        $("#addLevel1Li4").addClass("disabled");
                    }
                }
            }
            addLevel1GetUserLimit(addLevel1CurPage*10,10);
            if(addLevel1PageCounts<=1) {addLevel1PageCounts=1; $("#addLevel1Ul li").addClass("disabled")}
        }
    }
    //增加人员之搜索人员 level1SearchText
    function addLevel1Search(){
        var searchText=$("#level1SearchText").val();
//        alert(searchText);
        if(searchText!=''){
            $("#addLevel1Ul").hide();
            var phpUrl=url+'admin/Leader/LeaderLevel1AddSearch.php';
            $.ajax({
                url:phpUrl,
                type:"POST",
                async:true,
                data:{model:'addLevel1Search',searchText:searchText},
                success: function (data) {
//                alert(data);
                    data=JSON.parse(data);
                    if(data.state==1){
                        var tableData=data.data;
                        var Level1AddTable=$("#Level1AddTable");
                        Level1AddTable.empty();
                        for(var i=0;i<tableData.length;i++){
                            Level1AddTable.append(
                                    '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                    '<td class="td_center"><a class="ext_btn add" onclick="addLevel1ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                            );
                        }
                    }
                }
            });
        }
    }
    //增加人员之显示全部人员
    function addLevel1AllUser(){
        firstLastAddLevel1Page(0);
        $("#addLevel1Ul").show();
    }
    //添加level1领导之添加到部门
    function addLevel1ToLeader(e){
//        alert(e);
        var phpUrl=url+'admin/Leader/LeaderLevel1AddGetAllSection.php';
        var thisTr= e.parentNode.parentNode;
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'addLevel1GetAllSectionInfo',user_id:thisTr.childNodes[1].innerHTML},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                $("#level1UserName").val(thisTr.childNodes[2].innerHTML);
                $("#level1UserId").val(thisTr.childNodes[1].innerHTML);
                var Level1SelectSection=$("#Level1SelectSection");
                Level1SelectSection.empty();
                for(var i=0;i<data.data.length;i++){
                        Level1SelectSection.append('<option  value="'+data.data[i].section_ID+'" >'+data.data[i].section_name+'</option>');
                }
                var Level1Check=$("input[name='Level1Check']");
                Level1Check[0].checked=false;
                Level1Check[1].checked=false;
                if(data.state==1){
                    $("#dialogLevel1Div").dialog({
                        width:350,
                        resizable: false,
                        title:'添加部门审批领导-'+thisTr.childNodes[2].innerHTML,
                        modal: true,
                        buttons:{
                            '取消': function () {
                                $("#dialogLevel1Div").dialog('close');
                            },
                            '保存': function () {
                                var userId=$("#level1UserId").val();
                                var sectionId=$("#Level1SelectSection").val();

                                var isApprove=0;
                                if(Level1Check[0].checked==true) isApprove=1;
                                var isFee=0;
                                if(Level1Check[1].checked==true) isFee=1;
//                                alert('userId:'+userId+' sectionId:'+sectionId+' IsApprove;'+isApprove+' IsFee:'+isFee);
                                phpUrl=url+'admin/Leader/LeaderLevel1EditInsert.php';
                                $.ajax({
                                    url:phpUrl,
                                    type:"POST",
                                    async:true,
                                    data:{model:"editLevel1InsertInfo",userId:userId,sectionId:sectionId,isApprove:isApprove,isFee:isFee},
                                    success: function (data) {
//                                        alert(data);
                                        data=JSON.parse(data);
                                        if(data.state==1) {
                                            $("#dialogLevel1Div").dialog('close');
                                            getUserPageCount();
                                            addLevel1GetPageCount();
                                            addLevel1GetUserLimit(addLevel1CurPage*10,10);
                                            getLevel1Limit(level1CurPage*10,10);
                                            dialogInfo("保存成功！");
                                        }
                                        else dialogInfo("保存失败！");
                                    }
                                });
                            }
                        }
                    });
                }
            }
        });
    }
    //编辑level1某个部门的信息
    function editLevel1(e){
        var thisTr= e.parentNode.parentNode;
        var userId=thisTr.childNodes[1].innerHTML;
        var sectionName=thisTr.childNodes[3].innerHTML;
//        alert(userId);
//        alert(sectionName);
        var phpUrl=url+'admin/Leader/LeaderLevel1EditGetData.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'editLevel1GetInfo',userId:userId,sectionName:sectionName},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                $("#level1UserName").val(data.data[0].user_name);
                $("#level1UserId").val(data.data[0].user_id);
                var Level1SelectSection=$("#Level1SelectSection");
                Level1SelectSection.empty();
                for(var i=0;i<data.allsection.length;i++){
//                    alert(data.allsection[i].section_name);
                    if(data.allsection[i].section_name!=data.data[0].section_name)
                        Level1SelectSection.append('<option value="'+data.allsection[i].section_ID+'" >'+data.allsection[i].section_name+'</option>');
                    else
                        Level1SelectSection.append('<option selected value="'+data.allsection[i].section_ID+'" >'+data.allsection[i].section_name+'</option>');
                }

                var Level1Check=$("input[name='Level1Check']");
                if(data.data[0].is_approve==1) Level1Check[0].checked=true;else Level1Check[0].checked=false;
                if(data.data[0].is_fee==1)  Level1Check[1].checked=true; else Level1Check[1].checked=false;
                if(data.state==1){
                    $("#dialogLevel1Div").dialog({
                        width:350,
                        resizable: false,
                        title:'部门审批-'+data.data[0].user_name,
                        modal: true,
                        buttons:{
                            '取消': function () {
                                $("#dialogLevel1Div").dialog('close');
                            },
                            '保存': function () {
                                var userId=$("#level1UserId").val();
                                var sectionId=$("#Level1SelectSection").val();
                                var isApprove=0;
                                if(Level1Check[0].checked==true) isApprove=1;
                                var isFee=0;
                                if(Level1Check[1].checked==true) isFee=1;
//                                alert('userId:'+userId+' sectionId:'+sectionId+' IsApprove;'+isApprove+' IsFee:'+isFee);
                                phpUrl=url+'admin/Leader/LeaderLevel1EditUpdateData.php';
                                $.ajax({
                                    url:phpUrl,
                                    type:"POST",
                                    async:true,
                                    data:{model:"editLevel1UpdateInfo",userId:userId,sectionId:sectionId,sectionName:sectionName,isApprove:isApprove,isFee:isFee},
                                    success: function (data) {
//                                        alert(data);
                                        data=JSON.parse(data);
                                        if(data.state==1) {
                                            $("#dialogLevel1Div").dialog('close');
                                            getLevel1Limit(level1CurPage*10,10);
                                            dialogInfo("保存成功！");
                                        }
                                        else dialogInfo("保存失败！");
                                    }
                                });
                            }
                        }
                    });
                }
            }
        });
    }

    //删除level1
    function deleteLevel1(e){
//        alert(1);
        var thisTr= e.parentNode.parentNode;
        var userId=thisTr.childNodes[1].innerHTML;
        var sectionName=thisTr.childNodes[3].innerHTML;
//        alert(userId);
//        alert(sectionName);
        var phpUrl=url+'admin/Leader/LeaderLevel1DeleteData.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:"deleteLevel1Info",userId:userId,sectionName:sectionName},
            success: function (data) {
//              alert(data);
                data=JSON.parse(data);
                if(data.state==1) {
                    getLevel1Limit(level1CurPage*10,10);
                    getUserPageCount();
                    addLevel1GetPageCount();
                    dialogInfo("删除成功！");
                }
                else
                    dialogInfo("删除失败！");
            }
        });
    }
    //首尾跳页
    function firstLastLevel1Page(e){
//        alert(1);
        $("#level1Ul").show();
        if(e==0) {
            level1CurPage=0;
            $("#level1Ul li").addClass("disabled");
            $("#Level1Li3").removeClass("disabled");
            $("#Level1Li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            level1CurPage=level1PageCounts-1;
            $("#level1Ul li").addClass("disabled");
            $("#Level1Li1").removeClass("disabled");
            $("#Level1Li2").removeClass("disabled");
        }
        getLevel1Limit(level1CurPage*10,10);
        if(level1PageCounts<=1) {level1PageCounts=1; $("#level1Ul li").addClass("disabled")}
    }
    //上下翻页
    function upDownLevel1Page(e){
        $("#level1Ul").show();
        if(level1CurPage>=0||level1CurPage<=level1PageCounts-1){
            if(e<0){
                if(level1CurPage>0)  {
                    level1CurPage--;
                    if(level1CurPage>0) $("#level1Ul li").removeClass("disabled");
                    else{
                        $("#level1Ul li").removeClass("disabled");
                        $("#Level1Li1").addClass("disabled");
                        $("#Level1Li2").addClass("disabled");
                    }
                }
            }else{
                if(level1CurPage<level1PageCounts-1) {
                    level1CurPage++;
                    if(level1CurPage<level1PageCounts-1) $("#level1Ul li").removeClass("disabled");
                    else{
                        $("#level1Ul li").removeClass("disabled");
                        $("#Level1Li3").addClass("disabled");
                        $("#Level1Li4").addClass("disabled");
                    }
                }
            }
            getLevel1Limit(level1CurPage*10,10);
            if(level1PageCounts<=1) {level1PageCounts=1; $("#level1Ul li").addClass("disabled")}
        }
    }

    //**************************************************************
    //level2函数
    var level2CurPage=0;
    var level2PageCounts=1;
    //加载等级2表格
    function level2CreateTable(tableData){
        var i=0;
        var tableLevel2=$("#tableLevel2");
        tableLevel2.empty();
        for(;i<tableData.length;i++){
            tableLevel2.append(
                    '<tr><td class="td_center" >' +(i+1) + '</td>'+
                    '<td class="td_center  " >' + tableData[i]['user_id'] + '</td>'+
                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                    '<td class="td_center"><a class="ext_btn modify" onclick="editLevel2('+tableData[i]['user_id']+')" ><span class="modify" ></span>权限编辑</a>'+
                    '<a class="ext_btn del" onclick="deleteLevel2('+tableData[i]['user_id']+')" ><span class="del" ></span>删除</a></td></tr>'
            );
        }
    }
    //获取当前页数据
    function getLevel2Limit(n,m){
        var phpUrl=url+'admin/Leader/LeaderLevel2GetLimit.php';
        $.ajax({
            url:phpUrl,
            type:'POST',
            async:true,
            data:{model:'getLevel2Limit',n:n,m:m},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    level2CreateTable(data.data);
                }
            }
        });
    }
    //首页末页
    function firstLastLevel2Page(e){
//        alert(1);
        $("#level2Ul").show();
        if(e==0) {
            level2CurPage=0;
            $("#level2Ul li").addClass("disabled");
            $("#Level2Li3").removeClass("disabled");
            $("#Level2Li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            level2CurPage=level2PageCounts-1;
            $("#level2Ul li").addClass("disabled");
            $("#Level2Li1").removeClass("disabled");
            $("#Level2Li2").removeClass("disabled");
        }
        getLevel2Limit(level2CurPage*10,10);
        if(level2PageCounts<=1) {level2PageCounts=1; $("#level2Ul li").addClass("disabled")}
    }
    //上一页下一页
    function upDownLevel2Page(e){
//        alert(1);
        if(level2CurPage>=0||level2CurPage<=level2PageCounts-1){
            if(e<0){
                if(level2CurPage>0)  {
                    level2CurPage--;
                    if(level2CurPage>0) $("#level2Ul li").removeClass("disabled");
                    else{
                        $("#level2Ul li").removeClass("disabled");
                        $("#Level2Li1").addClass("disabled");
                        $("#Level2Li2").addClass("disabled");
                    }
                }
            }else{
                if(level2CurPage<level2PageCounts-1) {
                    level2CurPage++;
                    if(level2CurPage<level1PageCounts-1) $("#level2Ul li").removeClass("disabled");
                    else{
                        $("#level2Ul li").removeClass("disabled");
                        $("#Level2Li3").addClass("disabled");
                        $("#Level2Li4").addClass("disabled");
                    }
                }
            }
            getLevel2Limit(level2CurPage*10,10);
            if(level2PageCounts<=1) {level2PageCounts=1; $("#level2Ul li").addClass("disabled")}
        }
    }
    //编辑领导签批
    function editLevel2(e){
        window.localStorage.setItem('level2EditUserId',e);
        var phpUrl=url+'admin/Leader/LeaderLevel2EditGetData.php';
        $.ajax({
            url:phpUrl,
            type:'POST',
            async:true,
            data:{model:'editLevel2GetInfo',userId:e},
            success: function (data) {
//                alert(data);

                data=JSON.parse(data);

                if(data.state==1){
                    window.localStorage.setItem('LevelAllSection',JSON.stringify(data.allsection));
//                    alert(window.localStorage.getItem('LevelAllSection'));
                    var Level2IsApproveSelectSection=$('#Level2IsApproveSelectSection');
                    var allSectionData=data.allsection;
                    var isApproveSection=data.isApproveData==null ? '':data.isApproveData.section_id.split(',');
//                    alert(data.isFeeData);
                    var isFeeSection=data.isFeeData==null||data.isFeeData==''? '':data.isFeeData.section_id.split(',');
//                    alert(isApproveSection);
                    //加载isApprove
                    var level2TextAreaData='';
                    Level2IsApproveSelectSection.empty();
//                    Level2IsFeeSelectSection.empty();
                    for(var i= 0,flag=0;i<allSectionData.length;i++){
                        flag=0;
                        for(var j=0;j<isApproveSection.length;j++){
                            if(allSectionData[i].section_ID==isApproveSection[j]){
                                if(level2TextAreaData=='')
                                    level2TextAreaData=allSectionData[i].section_name;
                                else
                                    level2TextAreaData+=','+allSectionData[i].section_name;
                                flag=1;
                                break;
                            }
                        }
                        if(flag==0){
                            Level2IsApproveSelectSection.append(
                                    '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
                            );
                        }
                    }
                    $("#level2IsApproveSection").html(level2TextAreaData);
                    //加载isFee

                    var Level2IsFeeSelectSection=$("#Level2IsFeeSelectSection");
                    Level2IsFeeSelectSection.empty();
                    level2TextAreaData='';
//                    alert(Level2IsFeeSelectSection.html());
                    for(var i= 0,flag=0;i<allSectionData.length;i++){
                        flag=0;
                        for(var j=0;j<isFeeSection.length;j++){
                            if(allSectionData[i].section_ID==isFeeSection[j]){
                                if(level2TextAreaData=='')
                                    level2TextAreaData=allSectionData[i].section_name;
                                else
                                    level2TextAreaData+=','+allSectionData[i].section_name;
                                flag=1;
                                break;
                            }
                        }
                        if(flag==0){
                            Level2IsFeeSelectSection.append(
                                    '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
                            );
                        }
                    }
                    $("#level2IsFeeSection").html(level2TextAreaData);
                    $("#dialogLevel2Div").tabs().dialog({
                        title:'分管签批权限设置-'+e,
                        width:620,
                        resizable:false,
                        modal:true,
                        position: { my: "top-300px", at: "center", of: window  }
                    });
                }
            }
        });
    }
    //isApprove 为某个领导添加部门，
    function level2IsApproveAddSection(){
//       alert(window.localStorage.getItem('LevelAllSection'));
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
       // alert(allSectionData);
        var allTextArea=$("#level2IsApproveSection").html();
        var textArea=allTextArea.split(',');
        var Level2IsApproveSelectSection=$('#Level2IsApproveSelectSection');
        var addSectionData=Level2IsApproveSelectSection.val();
        var selectIndex=document.getElementById('Level2IsApproveSelectSection').selectedIndex;
        document.getElementById('Level2IsApproveSelectSection').options.remove(selectIndex);
//        alert(selectIndex);
        var flag=0;
        for(var j=0;j<textArea.length;j++){
            if(addSectionData==textArea[j]){
                    flag=1;
            }
        }
//        alert(Level2IsApproveSelectSection.val());
        if(flag==0){
            for(var i=0;i<allSectionData.length;i++){
                if(allSectionData[i].section_ID==addSectionData){
                    if(allTextArea==''||allTextArea==null){
                        $("#level2IsApproveSection").html(allSectionData[i].section_name);
                    }else{
                        $("#level2IsApproveSection").html(allTextArea+','+allSectionData[i].section_name);
                    }
                    break;
                }
            }
        }
    }
    //isApprove 清除某个人的部门，
    function level2IsApproveClearSection(){
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
        var Level2IsApproveSelectSection=$("#Level2IsApproveSelectSection");
        Level2IsApproveSelectSection.empty();
        for(var i= 0;i<allSectionData.length;i++){
            Level2IsApproveSelectSection.append(
                        '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
                );
        }
        $("#level2IsApproveSection").empty();
    }
    //isApprove 保存某个人的信息部门，
    function level2IsApproveSaveSection(){
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
        var level2IsApproveSection=$("#level2IsApproveSection").html().split(',');
        var section='';
        if(level2IsApproveSection!='') {
            for (var i = 0; i < level2IsApproveSection.length; i++) {
                for (var j = 0; j < allSectionData.length; j++)
                    if (level2IsApproveSection[i] == allSectionData[j].section_name) {
                        if (section == '') {
                            section = allSectionData[j].section_ID;
                        } else {
                            section += ',' + allSectionData[j].section_ID;
                        }
                    }
            }
        }
        var phpUrl=url+'admin/Leader/LeaderLevel2IsApproveSaveData.php';
        var level2EditUserId=window.localStorage.getItem('level2EditUserId');
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:"Level2IsApproveSaveData",userId:level2EditUserId,sectionId:section},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                {
                    if (data.state == 1) dialogInfo('保存成功');
                    getLevel2Limit(level1CurPage*10,10);
                }
            }
        });
    }
    //level2 isFee 为某个人添加部门
    function level2IsFeeAddSection(){
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
        var allTextArea=$("#level2IsFeeSection").html();
//        alert(allTextArea);
        var textArea=allTextArea.split(',');
        var Level2IsFeeSelectSection=$('#Level2IsFeeSelectSection');
        var addSectionData=Level2IsFeeSelectSection.val();
        var selectIndex=document.getElementById('Level2IsFeeSelectSection').selectedIndex;
        document.getElementById('Level2IsFeeSelectSection').options.remove(selectIndex);
//        alert(selectIndex);
        var flag=0;
        for(var j=0;j<textArea.length;j++){
            if(addSectionData==textArea[j]){
                flag=1;
            }
        }
//        alert(addSectionData);
//        alert(Level2IsApproveSelectSection.val());
        if(flag==0){
            for(var i=0;i<allSectionData.length;i++){
                if(allSectionData[i].section_ID==addSectionData){
                    if(allTextArea==''||allTextArea==null){
//                        alert(allSectionData[i].section_name);
                        $("#level2IsFeeSection").html(allSectionData[i].section_name);
                    }else{
//                        alert(allSectionData[i].section_name);
                        $("#level2IsFeeSection").html(allTextArea+','+allSectionData[i].section_name);
                    }
                    break;
                }
            }
        }
    }
    //level2 isFee 清除某个人的部门，
    function level2IsFeeClearSection(){
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
        var Level2IsFeeSelectSection=$("#Level2IsFeeSelectSection");
        Level2IsFeeSelectSection.empty();
        for(var i= 0;i<allSectionData.length;i++){
            Level2IsFeeSelectSection.append(
                    '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
            );
        }
        $("#level2IsFeeSection").empty();
    }
    //isFee 保存某个人的信息部门，
    function level2IsFeeSaveSection(){
        var allSectionData=JSON.parse(window.localStorage.getItem('LevelAllSection'));
        var level2IsFeeSection=$("#level2IsFeeSection").html().split(',');
        var section='';
        if(level2IsFeeSection!='') {
            for (var i = 0; i < level2IsFeeSection.length; i++) {
                for (var j = 0; j < allSectionData.length; j++)
                    if (level2IsFeeSection[i] == allSectionData[j].section_name) {
                        if (section == '') {
                            section = allSectionData[j].section_ID;
                        } else {
                            section += ',' + allSectionData[j].section_ID;
                        }
                    }
            }
        }
        var phpUrl=url+'admin/Leader/LeaderLevel2IsFeeSaveData.php';
        var level2EditUserId=window.localStorage.getItem('level2EditUserId');
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:"Level2IsFeeSaveData",userId:level2EditUserId,sectionId:section},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                {
                    if (data.state == 1) dialogInfo('保存成功');
                    getLevel2Limit(level1CurPage*10,10);
                }
            }
        });
    }
    //level2 之添加领导
    function addLevel2Leader(){
        $("#dialogLevel2AddDiv").dialog({
            position: { my: "top-300px", at: "center", of: window  } ,
            title:'添加分管签批领导',
            modal:true,
            resizable:false,
            width:600
        });

        addLevel2GetPageCount();
//        alert(addLevel2PageCounts);
        addLevel2GetUserLimit(0,10);
    }
    //添加level2领导之加获取人员数量
    function addLevel2GetPageCount(){
        var phpUrl=url+'admin/Leader/LeaderLevel2AddGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'addLevel2GetPageCount'},
            success: function (data) {
//                alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    addLevel2PageCounts = Math.ceil(data.pageCount/10);
                    if(addLevel2PageCounts<=1) {addLevel2PageCounts=1; $("#addLevel2Ul li").addClass("disabled") } else {$("#addLevel2Ul li").removeClass("disabled")}
                }
            }
        });
    }
    var addLevel2CurPage=0;
    var addLevel2PageCounts=1;
    //level2 之添加领导 之加载数据
    function addLevel2GetUserLimit(n,m){
        var phpUrl=url+'admin/Leader/LeaderLevel2AddGetUserLimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'addLevel2GetUserlimit',n:n,m:m},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    var tableData=data.data;
                    var Level2AddTable=$("#Level2AddTable");
                    Level2AddTable.empty();
                    for(var i=0;i<tableData.length;i++){
                        Level2AddTable.append(
                                '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                '<td class="td_center"><a class="ext_btn add" onclick="addLevel2ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                        );
                    }
                }
            }
        });
    }
    //添加level2领导之首尾页
    function firstLastAddLevel2Page(e){
//        alert(1);
        if(e==0) {
            addLevel2CurPage=0;
            $("#addLevel2Ul li").addClass("disabled");
            $("#addLevel2Li3").removeClass("disabled");
            $("#addLevel2Li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            addLevel2CurPage=addLevel2PageCounts-1;
            $("#addLevel2Ul li").addClass("disabled");
            $("#addLevel2Li1").removeClass("disabled");
            $("#addLevel2Li2").removeClass("disabled");
        }
        addLevel2GetUserLimit(addLevel2CurPage*10,10);
        if(addLevel2PageCounts<=1) {addLevel2PageCounts=1; $("#addLevel2Ul li").addClass("disabled")}
    }
    //添加level2领导之上下页
    function upDownAddLevel2Page(e){
        if(addLevel2CurPage>=0||addLevel2CurPage<=addLevel2PageCounts-1){
            if(e<0){
                if(addLevel2CurPage>0)  {
                    addLevel2CurPage--;
                    if(addLevel2CurPage>0) $("#addLevel2Ul li").removeClass("disabled");
                    else{
                        $("#addLevel2Ul li").removeClass("disabled");
                        $("#addLevel2Li1").addClass("disabled");
                        $("#addLevel2Li2").addClass("disabled");
                    }
                }
            }else{
                if(addLevel2CurPage<addLevel2PageCounts-1) {
                    addLevel2CurPage++;
                    if(addLevel2CurPage<addLevel2PageCounts-1) $("#level2Ul li").removeClass("disabled");
                    else{
                        $("#addLevel2Ul li").removeClass("disabled");
                        $("#addLevel2Li3").addClass("disabled");
                        $("#addLevel2Li4").addClass("disabled");
                    }
                }
            }
            addLevel2GetUserLimit(addLevel2CurPage*10,10);
            if(addLevel2PageCounts<=1) {addLevel2PageCounts=1; $("#addLevel2Ul li").addClass("disabled")}
        }
    }
    function addLevel2Search(){
        var searchText=$("#level2SearchText").val();
        if(searchText!=''){
            $('#addLevel2Ul').hide();
            var phpUrl=url+'admin/Leader/LeaderLevel2AddSearch.php';
            $.ajax({
                url:phpUrl,
                type:"POST",
                async:true,
                data:{model:'addLevel2Search',searchText:searchText},
                success: function (data) {
//                alert(data);
                    data=JSON.parse(data);
                    if(data.state==1){
                        var tableData=data.data;
                        var Level2AddTable=$("#Level2AddTable");
                        Level2AddTable.empty();
                        if(!tableData){
                            return;
                        }
                        for(var i=0;i<tableData.length;i++){
                            Level2AddTable.append(
                                    '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                    '<td class="td_center"><a class="ext_btn add" onclick="addLevel2ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                            );
                        }
                    }
                }
            });
        }


    }
    //增加人员之显示全部人员
    function addLevel2AllUser(){
        firstLastAddLevel2Page(0);
        $('#addLevel2Ul').show();
    }
    //添加level2领导之保存数据
    function addLevel2ToLeader(e){
        var phpUrl=url+'admin/Leader/LeaderGetAllSection.php';
        var thisTr= e.parentNode.parentNode;
        var addLevel2UserName=thisTr.childNodes[2].innerHTML;
        var addLevel2UserId=thisTr.childNodes[1].innerHTML;
//        alert(addLevel2UserId);
        window.localStorage.setItem('level2EditUserId',addLevel2UserId);
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'getAllSection'},
            success: function (data) {
//                alert(data);
                        data=JSON.parse(data);
                        if(data.state==1){
                            var Level2IsApproveSelectSection=$('#Level2IsApproveSelectSection');
                            var allSectionData=data.allsection;

                            window.localStorage.setItem('LevelAllSection', JSON.stringify(allSectionData));
                            //加载isApprove
                            Level2IsApproveSelectSection.empty();
                            for(var i= 0;i<allSectionData.length;i++){
                                    Level2IsApproveSelectSection.append(
                                            '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
                                    );
                            }
                            //加载isFee
                            var Level2IsFeeSelectSection=$("#Level2IsFeeSelectSection");
                            Level2IsFeeSelectSection.empty();
                            for(var i= 0;i<allSectionData.length;i++){
                                    Level2IsFeeSelectSection.append(
                                            '<option value="'+allSectionData[i].section_ID+'">'+allSectionData[i].section_name+'</option>'
                                    );
                            }
                            $("#level2IsApproveSection").empty();
                            $("#level2IsFeeSection").empty();
                            $("#dialogLevel2Div").tabs().dialog({
                                title:'分管签批权限设置-'+addLevel2UserId,
                                width:620,
                                resizable:false,
                                modal:true,
                                position: { my: "top-300px", at: "center", of: window  }
                            });
                            getUserPageCount();
                            addLevel2GetPageCount();
                            addLevel2GetUserLimit(addLevel2CurPage*10,10);
                            getLevel2Limit(level1CurPage*10,10);
                        }
            }
        });
    }
    //删除level2
    function deleteLevel2(e){
//        alert(e);
        var phpUrl=url+'admin/Leader/LeaderLevel2DeleteData.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:"deleteLevel2Info",userId:e},
            success: function (data) {
//              alert(data);
                data=JSON.parse(data);
                if(data.state==1) {
                    getUserPageCount();
                    addLevel2GetPageCount();
                    getLevel2Limit(level1CurPage*10,10);
                    dialogInfo("删除成功！");
                }
                else
                    dialogInfo("删除失败！");
            }
        });
    }
    //**************************************************************
    //level3函数
    var level3CurPage=0;
    var level3PageCounts=1;
    //加载等级3表格
    function level3CreateTable(tableData){
        var i=0;
        var tableLevel3=$("#tableLevel3");
        tableLevel3.empty();
        var isApproveChecked='';
        var isFeeChecked='';
        for(;i<tableData.length;i++){
            isApproveChecked=tableData[i]['is_approve']==1?'checked':'';
            isFeeChecked=tableData[i]['is_fee']==1?'checked':'';
            tableLevel3.append(
                    '<tr><td class="td_center" >' +(i+1) + '</td>'+
                    '<td class="td_center  "  style="display:none;">' + tableData[i]['user_id'] + '</td>'+
                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                    '<td class="td_center  " ><input type="checkbox" style="margin:0 3px 3px 0;"'+isApproveChecked+' >审批权限</td>'+
                    '<td class="td_center  " ><input type="checkbox" style="margin:0 3px 3px 0;"'+isFeeChecked+' >财务权限</td>'+
                    '<td class="td_center"><a class="ext_btn modify" onclick="saveLevel3Leader(this)" ><span class="modify" ></span>保存</a>'+
                    '<a class="ext_btn del" onclick="deleteLevel3('+tableData[i]['user_id']+')" ><span class="del" ></span>删除</a></td></tr>'
            );
        }
    }
    //获取当前页数据
    function getLevel3Limit(){
        var phpUrl=url+'admin/Leader/LeaderLevel3GetLimit.php';
        $.ajax({
            url:phpUrl,
            type:'POST',
            async:true,
            data:{model:'getLevel3Limit'},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    level3CreateTable(data.data);
                }
            }
        });
    }
    //存储数据
    function saveLevel3Leader(e){
        var phpUrl=url+'admin/Leader/LeaderLevel3SaveLeader.php';
//        alert(1);
        var thisTr= e.parentNode.parentNode;
//        alert(thisTr.innerHTML);
        var userId=thisTr.childNodes[1].innerHTML;
//        alert(userId);
        var isApprove=thisTr.childNodes[3].childNodes[0].checked?1:0;
        var isFee=thisTr.childNodes[4].childNodes[0].checked?1:0;
//        alert(userId+":"+isApprove+":"+isFee);
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:"saveLevel3Leader",userId:userId,isApprove:isApprove,isFee:isFee},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    getLevel3Limit();
                    dialogInfo('保存成功！');
                }
            }
        });
    }
    //level3 删除数据
    function deleteLevel3(e){
        var phpUrl=url+'admin/Leader/LeaderLevel3Delete.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'deleteLevel3Info',userId:e},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    getLevel3Limit();
                    dialogInfo('删除成功！');
                }else{
                    dialogInfo('删除失败！');
                }
            }
        });
    }
    //添加领导
    function addLevel3Leader(){
        $("#dialogLevel3AddDiv").dialog({
            position: { my: "top-300px", at: "center", of: window  } ,
            title:'添加领导签批领导',
            modal:true,
            resizable:false,
            width:600
        });
        addLevel3GetPageCount();
//        alert(addLevel3PageCounts);
        addLevel3GetUserLimit(0,10);
    }
    //添加level3领导之加获取人员数量
    function addLevel3GetPageCount(){
        var phpUrl=url+'admin/Leader/LeaderLevel3AddGetPageCount.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:false,
            data:{model:'addLevel3GetPageCount'},
            success: function (data) {
//                alert(data);
                data = JSON.parse(data);
                if (data.state == 1) {
                    addLevel3PageCounts = Math.ceil(data.pageCount/10);
                    if(addLevel3PageCounts<=1) {addLevel3PageCounts=1; $("#addLevel3Ul li").addClass("disabled") } else {$("#addLevel3Ul li").removeClass("disabled")}
                }
            }
        });
    }
    var addLevel3CurPage=0;
    var addLevel3PageCounts=1;
    //level3 之添加领导 之加载数据
    function addLevel3GetUserLimit(n,m){
        var phpUrl=url+'admin/Leader/LeaderLevel3AddGetUserlimit.php';
        $.ajax({
            url:phpUrl,
            type:"POST",
            async:true,
            data:{model:'addLevel3GetUserlimit',n:n,m:m},
            success: function (data) {
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    var tableData=data.data;
                    var Level3AddTable=$("#Level3AddTable");
                    Level3AddTable.empty();
                    for(var i=0;i<tableData.length;i++){
                        Level3AddTable.append(
                                '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                '<td class="td_center"><a class="ext_btn add" onclick="addLevel3ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                        );
                    }
                }
            }
        });
    }
    //添加level3领导之首尾页
    function firstLastAddLevel3Page(e){
//        alert(1);
        if(e==0) {
            addLevel3CurPage=0;
            $("#addLevel3Ul li").addClass("disabled");
            $("#addLevel3Li3").removeClass("disabled");
            $("#addLevel3Li4").removeClass("disabled");
        }
        else{
//      alert(pageCounts);
            addLevel3CurPage=addLevel3PageCounts-1;
            $("#addLevel3Ul li").addClass("disabled");
            $("#addLevel3Li1").removeClass("disabled");
            $("#addLevel3Li2").removeClass("disabled");
        }
        addLevel3GetUserLimit(addLevel3CurPage*10,10);
        if(addLevel3PageCounts<=1) {addLevel3PageCounts=1; $("#addLevel3Ul li").addClass("disabled")}
    }
    //添加level3领导之上下页
    function upDownAddLevel3Page(e){
        if(addLevel3CurPage>=0||addLevel3CurPage<=addLevel3PageCounts-1){
            if(e<0){
                if(addLevel3CurPage>0)  {
                    addLevel3CurPage--;
                    if(addLevel3CurPage>0) $("#addLevel3Ul li").removeClass("disabled");
                    else{
                        $("#addLevel3Ul li").removeClass("disabled");
                        $("#addLevel3Li1").addClass("disabled");
                        $("#addLevel3Li2").addClass("disabled");
                    }
                }
            }else{
                if(addLevel3CurPage<addLevel3PageCounts-1) {
                    addLevel3CurPage++;
                    if(addLevel3CurPage<addLevel2PageCounts-1) $("#level3Ul li").removeClass("disabled");
                    else{
                        $("#addLevel3Ul li").removeClass("disabled");
                        $("#addLevel3Li3").addClass("disabled");
                        $("#addLevel3Li4").addClass("disabled");
                    }
                }
            }
            addLevel3GetUserLimit(addLevel3CurPage*10,10);
            if(addLevel3PageCounts<=1) {addLevel3PageCounts=1; $("#addLevel3Ul li").addClass("disabled")}
        }
    }
    function addLevel3Search(){
        var searchText=$("#level3SearchText").val();
        if(searchText!=''){
            $('#addLevel3Ul').hide();
            var phpUrl=url+'admin/Leader/LeaderLevel3AddSearch.php';
            $.ajax({
                url:phpUrl,
                type:"POST",
                async:true,
                data:{model:'addLevel3Search',searchText:searchText},
                success: function (data) {
//                alert(data);
                    data=JSON.parse(data);
                    if(data.state==1){
                        var tableData=data.data;
                        var Level3AddTable=$("#Level3AddTable");
                        Level3AddTable.empty();
                        for(var i=0;i<tableData.length;i++){
                            Level3AddTable.append(
                                    '<tr><td class="td_center" >' +(i+1) + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_ID'] + '</td>'+
                                    '<td class="td_center  " >' + tableData[i]['user_name'] + '</td>'+
                                    '<td class="td_center"><a class="ext_btn add" onclick="addLevel3ToLeader(this)" ><span class="add" ></span>添加</a></td></tr>'
                            );
                        }
                    }
                }
            });
        }


    }
    //增加人员之显示全部人员
    function addLevel3AllUser(){
        firstLastAddLevel3Page(0);
        $('#addLevel3Ul').show();
    }
    //添加为领导签批
    function addLevel3ToLeader(e){
        var thisTr= e.parentNode.parentNode;
        var userId=thisTr.childNodes[1].innerHTML;
        var userName=thisTr.childNodes[2].innerHTML;
        var Level3IsApprove=document.getElementById('Level3IsApprove');
        Level3IsApprove.checked=false;
        var Level3IsFee=document.getElementById('Level3IsFee');
        Level3IsFee.checked=false;
        $('#level3UserName').val(userName);
        $("#dialogLevel3Div").dialog({
            width: 350,
            resizable: false,
            title: '添加领导签批-' + userName,
            modal: true,
            buttons:{
                '取消': function () {
                    $("#dialogLevel3Div").dialog('close');
                },
                '确定': function () {
                    var phpUrl=url+'admin/Leader/LeaderLevel3SaveLeader.php';
                    var isApprove=Level3IsApprove.checked?1:0;
                    var isFee=Level3IsFee.checked?1:0;
                    $.ajax({
                        url:phpUrl,
                        type:"POST",
                        async:true,
                        data:{model:"saveLevel3Leader",userId:userId,isApprove:isApprove,isFee:isFee},
                        success: function (data) {
//                            alert(data);
                            data=JSON.parse(data);
                            if(data.state==1){
                                getLevel3Limit();
                                dialogInfo('保存成功！');
                                $("#dialogLevel3Div").dialog('close');
                            }else{
                                dialogInfo('保存失败！');
                            }
                        }
                    });
                }
            }
        });
    }
</script>
</html>